﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineStore.Dal;
using OnlineStore.Bll;

namespace OnlineStore.Gui
{
    public partial class Login : System.Web.UI.Page
    {
        string UserName, PassWord;
        bizUser _bizUser = new bizUser();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                UserName = tb_Username.Text;
                PassWord = tb_PassWord.Text;
            }
            if (Request.QueryString.Get("logout") == "true")
            {
                Session.Clear();
            }
            if (Session["user"] != null)
            {
                HL_tab_login.NavigateUrl = "/gui/Account.aspx";
                HL_tab_login.Text = ((tbCustomer)Session["user"]).Username;
                HL_tab_Logout.Visible = true;
            }
            ListCartRight.DataSource = (List<bizCart>)Session["cart"];
            ListCartRight.DataBind();
            lb_Sum.Text = String.Format("{0:0,0 VNĐ}", bizCart.SumAllList((List<bizCart>)Session["cart"]));
            lb_Sum_product.Text = String.Format("{0:0,0 VNĐ}", bizCart.SumAllList((List<bizCart>)Session["cart"]));
        }

        protected void OnSubmit(object sender, EventArgs e)
        {
            tbCustomer _user = _bizUser.LoginUser(tb_Username.Text, tb_PassWord.Text);
            if (_user != null)
            {
                Session["user"] = _user;
                Response.Redirect("/gui/Account.aspx", true);
            }
            lb_warning_login.Visible = true;
        }
    }
}